package com.norma.netty.study.netty.disruptor;

import com.norma.netty.study.netty.disruptor.core.MessageProducer;
import com.norma.netty.study.netty.disruptor.core.RingBufferWorkerPoolFactory;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author zhangchaofeng
 * @date 2021/1/5
 * @description
 */
public class NettyServerHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        TransData data = (TransData) msg;
//        System.out.println("server端接收到数据" + data.toString());
//        TransData respData = new TransData();
//        respData.setId(data.getId());
//        respData.setMessage(data.getMessage());
//        respData.setName(data.getName());
//        ctx.writeAndFlush(respData);

        /**需要有自己的ID生成策略*/
        MessageProducer messageProducer = RingBufferWorkerPoolFactory.getInstance().getMessageProducer("event-producer-1");
        messageProducer.sendData(ctx, data);
    }


}
